package com.leyou.item.web;

import com.leyou.item.entity.Goods;
import com.leyou.item.entity.SearchList;
import com.leyou.item.service.SearchGoodsService;
import com.leyou.starter.elastic.entity.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/goods")
public class SearchController {

    @Autowired
    SearchGoodsService searchGoodsService;

    @GetMapping("/suggestion")
    public Mono<List<String>> getSuggestion(@RequestParam("key") String key) {
        return searchGoodsService.getSuggestion(key);
    }

    @PostMapping("/list")
    public Mono<PageInfo<Goods>> getList(@RequestBody SearchList list) {
        return searchGoodsService.getList(list);
    }

    @PostMapping("/filter")
    public Mono<Map> getFilter(@RequestBody SearchList list) {
        return searchGoodsService.getFilter(list);
    }
}
